package nl.boelen.game.server.entity;

import java.net.InetAddress;

import nl.boelen.game.net.packet.Packet;
import nl.boelen.game.net.packet.Packet31Movement;

public class PlayerMP {

    private String userName;
    private String uniqueKey;
    private byte movingDirection;
    private int x;
    private int y;
    private int hp;
    private int maxhp;
    private int UDPport;
    private int shirtColor;
    private int TCPport;
    private long lastChecked;
    private boolean isChecking = false;
    private InetAddress ip;

    public PlayerMP(int x, int y, String userName, InetAddress ip, int UDPport, int TCPport, String uniqueKey, int shirtColor, int movingDirection, int maxhp) {
        this.x = x;
        this.y = y;
        this.ip = ip;
        this.maxhp = maxhp;
        this.hp = maxhp;
        this.UDPport = UDPport;
        this.TCPport = TCPport;
        this.userName = userName;
        this.uniqueKey = uniqueKey;
        this.shirtColor = shirtColor;
        this.movingDirection = (byte) movingDirection;
        this.lastChecked = System.currentTimeMillis();
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setIp(InetAddress ip) {
        this.ip = ip;
    }

    public void setPort(int port) {
        this.UDPport = port;
    }

    public void setTCPPort(int port) {
        this.TCPport = port;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void setUniqueKey(String uniqueKey) {
        this.uniqueKey = uniqueKey;
    }

    public void setShirtColor(int shirtColor) {
        this.shirtColor = shirtColor;
    }

    public void setMovingDirection(byte movingDirection) {
        this.movingDirection = movingDirection;
    }
    
    public void setMaxhp(int maxhp){
        this.maxhp = maxhp;
    }
    
    public void setHp(int hp){
        this.hp = hp;
    }

    public void hasChecked() {
        this.lastChecked = System.currentTimeMillis();
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public InetAddress getIp() {
        return ip;
    }

    public int getUDPPort() {
        return UDPport;
    }

    public int getTCPPort() {
        return TCPport;
    }

    public String getUserName() {
        return userName;
    }

    public String getUniqueKey() {
        return uniqueKey;
    }

    public int getShirtColor() {
        return shirtColor;
    }

    public byte getMovingDirection() {
        return movingDirection;
    }

    public int getMaxhp(){
        return maxhp;
    }
    
    public int getHp(){
        return hp;
    }
    
    public String toString() {
        return this.userName;
    }

    public String getMovingDirectionAsString() {
        switch (this.movingDirection) {
            case 0:
                return "Up";
            case 1:
                return "Down";
            case 2:
                return "Left";
            case 3:
                return "Right";
            default:
                return "";
        }
    }

    public long getLastChecked() {
        return this.lastChecked;
    }

    public void hasMoved(Packet packet) {
        hasChecked();
        this.x = ((Packet31Movement) packet).getX();
        this.y = ((Packet31Movement) packet).getY();
        this.movingDirection = ((Packet31Movement) packet).getMovingDirection();
    }

    public boolean isChecking() {
        return this.isChecking;
    }

    public void checking() {
        this.isChecking = true;
    }

    public void checked() {
        hasChecked();
        this.isChecking = false;
    }
}
